package models

import (
	"fmt"

	"gorm.io/gen"
	"gorm.io/gorm"
)

func Gen(db *gorm.DB) {

	genConfig := gen.Config{
		OutPath:      "./models/dao",
		ModelPkgPath: "./model",
		Mode:         gen.WithDefaultQuery | gen.WithQueryInterface,
	}

	genConfig.WithOpts(gen.FieldJSONTagWithNS(func(columnName string) (tagContent string) {
		return fmt.Sprintf("%s,omitempty", columnName)
	}))

	// 初始化数据库连接
	g := gen.NewGenerator(genConfig)
	g.UseDB(db)

	cspMtRegional := g.GenerateModel("csp_mt_regional")
	cspUser := g.GenerateModel("csp_user")
	// g.GenerateAllTable()
	g.ApplyBasic(cspMtRegional, cspUser)
	g.Execute()
}
